<?php

require_once '../include/common.php';
ignore_user_abort();
set_time_limit(0); 
$file = "cache/shuo.db";
$hs_num = file_get_contents($file);
$hs= $hs_num + 1;
file_put_contents($file, $hs);

function scpost($url,$post){
	$ch= curl_init(); 
	curl_setopt($ch, CURLOPT_URL, $url);       
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn; R815T Build/JOP40D) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.5 Mobile Safari/533.1'); 
	curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 
	curl_setopt($ch, CURLOPT_POST, 1); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
	curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$result = curl_exec($ch);
	curl_close($ch);
	return $result;
} 

function surl($content="wnyr",$sid,$qq,$sname,$richval,$lon="",$lat=""){
	$url='http://m.qzone.com/mood/publish_mood';
	$post='content='.$content.'++&sid='.$sid.'&lon='.$lon.'&lbsid=&res_uin='.$qq.'&richval='.urlencode($richval).'&source_name='.$sname.'&is_winphone=2&opr_type=publish_shuoshuo&format=json&issyncweibo=0&lat='.$lat;
	return scpost($url,$post);
}

function w_shuo($qq,$sid,$sname,$sdata,$file){
	$content=($sdata!="")?w_ubb($sdata).$ad:"";
	$file=($file!="")?m_ubb($file):"";
if((!empty($sid))&&(!empty($qq))){
	$file = realpath($file);
	$image_size = @getimagesize($file); 
	$image=@file_get_contents($file);
	$url="http://up.qzone.com/cgi-bin/upload/cgi_upload_pic_v2";
	$post="picture=".urlencode(base64_encode($image))."&base64=1&hd_height=".$image_size[1]."&hd_width=".$image_size[0]."&hd_quality=90&output_type=json&preupload=1&charset=utf-8&output_charset=utf-8&logintype=sid&Exif_CameraMaker=&Exif_CameraModel=&Exif_Time=&uin=".$qq."&sid=".$sid;
	$data=preg_replace("/\s/","",scpost($url,$post));
	preg_match('/_Callback\((.*)\);/',$data,$arr);
	$data=json_decode($arr[1],true);
	$post="output_type=json&preupload=2&md5=".$data[filemd5]."&filelen=".$data[filelen]."&batchid=".time().rand(100000,999999)."&currnum=0&uploadNum=1&uploadtime=".time()."&uploadtype=1&upload_hd=0&albumtype=7&big_style=1&op_src=15003&charset=utf-8&output_charset=utf-8&uin=".$qq."&sid=".$sid."&logintype=sid&refer=shuoshuo";
	$img=preg_replace("/\s/","",scpost($url,$post));
	preg_match('/_Callback\(\[(.*)\]\);/',$img,$arr);
	$data=json_decode($arr[1],true);
	$richval=($data[picinfo][albumid]!="")?"{$data[picinfo][albumid]},{$data[picinfo][lloc]},{$data[picinfo][sloc]},{$data[picinfo][type]},{$data[picinfo][height]},{$data[picinfo][width]},,,":"";
	$result=surl($content,$sid,$qq,$sname,$richval,$lon,$lat);
}
	
	

}

	$z_sql = "SELECT `gqid` FROM `w_qq` WHERE shuo='1' AND zt='1'";
	$z_sth = $db->query($z_sql);
	$z_num = $z_sth->rowCount();
	
	$num=ceil($z_num / $run_num);
	

	$now_num=($hs_num%$num)*$run_num;
	
	$shuo_sql = "SELECT `qq`, `sid`, `sname`, `sdata`, `sfile` FROM `w_qq` WHERE shuo='1' AND zt='1' limit {$now_num},{$run_num}";
	$shuo_sth = $db->query($shuo_sql);
	$shuo=$shuo_sth->fetchAll();

	foreach ($shuo as $value) {
		w_shuo($value[qq],$value[sid],$value[sname],$value[sdata],$value[sfile]);
		
	}
	
echo 'ok';
?>